<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
include('../../includes/classes/core.php');
$action 	= $_REQUEST['act'];
$data 		= '';
$error		= '';
		
switch ($action) {	
	case 'get_list':
		$count = $_REQUEST['count'];
	    	    
		$rResult = mysql_query("SELECT		`client_objects`.`id`,
									 		CONCAT(client.`name`, '(', client_objects.`name`,  ')' ) AS `client`,
								           `ian1`.`degree_type` AS ian1,
								           `ian2`.`degree_type` AS ian2,
								           `teb1`.`degree_type` AS teb1,
								           `teb2`.`degree_type` AS teb2,
								           `mar1`.`degree_type` AS mar1,
								           `mar2`.`degree_type` AS mar2,
								           `apr1`.`degree_type` AS apr1,
								           `apr2`.`degree_type` AS apr2,
								           `mai1`.`degree_type` AS mai1,
								           `mai2`.`degree_type` AS mai2,
								           `ivn1`.`degree_type` AS ivn1,
								           `ivn2`.`degree_type` AS ivn2,
								           `ivl1`.`degree_type` AS ivl1,
								           `ivl2`.`degree_type` AS ivl2,
								           `agv1`.`degree_type` AS agv1,
								           `agv2`.`degree_type` AS agv2,
								           `seq1`.`degree_type` AS seq1,
								           `seq2`.`degree_type` AS seq2,
								           `oqt1`.`degree_type` AS oqt1,
								           `oqt2`.`degree_type` AS oqt2,
								           `noe1`.`degree_type` AS noe1,
								           `noe2`.`degree_type` AS noe2,
								           `dec1`.`degree_type` AS dec1,
								           `dec2`.`degree_type` AS dec2
						        FROM  		`client_objects` 
						        LEFT JOIN `client` ON client.id = client_objects.client_id
						        LEFT JOIN services_degree AS `ian1`  ON DAYOFMONTH(`ian1`.call_date) BETWEEN 0 AND 16  && MONTH(`ian1`.call_date) = 1 && `ian1`.`client_object` = `client_objects`.`id` && YEAR(`ian1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `ian2`  ON DAYOFMONTH(`ian2`.call_date) BETWEEN 17 AND 31 && MONTH(`ian2`.call_date) = 1 && `ian2`.`client_object` = `client_objects`.`id` && YEAR(`ian2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `teb1`  ON DAYOFMONTH(`teb1`.call_date) BETWEEN 0 AND 16  && MONTH(`teb1`.call_date) = 2 && `teb1`.`client_object` = `client_objects`.`id` && YEAR(`teb1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `teb2`  ON DAYOFMONTH(`teb2`.call_date) BETWEEN 17 AND 31 && MONTH(`teb2`.call_date) = 2 && `teb2`.`client_object` = `client_objects`.`id` && YEAR(`teb2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `mar1` ON DAYOFMONTH(`mar1`.call_date) BETWEEN 0 AND 16  && MONTH(`mar1`.call_date) = 3 && `mar1`.`client_object` = `client_objects`.`id` && YEAR(`mar1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `mar2` ON DAYOFMONTH(`mar2`.call_date) BETWEEN 17 AND 31 && MONTH(`mar2`.call_date) = 3 && `mar2`.`client_object` = `client_objects`.`id` && YEAR(`mar2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `apr1`  ON DAYOFMONTH(`apr1`.call_date) BETWEEN 0 AND 16  && MONTH(`apr1`.call_date) = 4 && `apr1`.`client_object` = `client_objects`.`id` && YEAR(`apr1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `apr2`  ON DAYOFMONTH(`apr2`.call_date) BETWEEN 17 AND 31 && MONTH(`apr2`.call_date) = 4 && `apr2`.`client_object` = `client_objects`.`id` && YEAR(`apr2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `mai1`  ON DAYOFMONTH(`mai1`.call_date) BETWEEN 0 AND 16  && MONTH(`mai1`.call_date) = 5 && `mai1`.`client_object` = `client_objects`.`id` && YEAR(`mai1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `mai2`  ON DAYOFMONTH(`mai2`.call_date) BETWEEN 17 AND 31 && MONTH(`mai2`.call_date) = 5 && `mai2`.`client_object` = `client_objects`.`id` && YEAR(`mai2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `ivn1`   ON DAYOFMONTH(`ivn1`.call_date) BETWEEN 0 AND 16 && MONTH(`ivn1`.call_date) = 6 && `ivn1`.`client_object` = `client_objects`.`id` && YEAR(`ivn1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `ivn2`   ON DAYOFMONTH(`ivn2`.call_date) BETWEEN 17 AND 31 && MONTH(`ivn2`.call_date) = 6 && `ivn2`.`client_object` = `client_objects`.`id` && YEAR(`ivn2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `ivl1`    ON DAYOFMONTH(`ivl1`.call_date) BETWEEN 0 AND 16 && MONTH(`ivl1`.call_date) = 7 && `ivl1`.`client_object` = `client_objects`.`id` && YEAR(`ivl1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `ivl2`    ON DAYOFMONTH(`ivl2`.call_date) BETWEEN 17 AND 31&& MONTH(`ivl2`.call_date) = 7 && `ivl2`.`client_object` = `client_objects`.`id` && YEAR(`ivl2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `agv1` ON DAYOFMONTH(`agv1`.call_date) BETWEEN 0 AND 16 && MONTH(`agv1`.call_date) = 8 && `agv1`.`client_object` = `client_objects`.`id` && YEAR(`agv1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `agv2` ON DAYOFMONTH(`agv2`.call_date) BETWEEN 17 AND 31 && MONTH(`agv2`.call_date) = 8 && `agv2`.`client_object` = `client_objects`.`id` && YEAR(`agv2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `seq1` ON DAYOFMONTH(`seq1`.call_date) BETWEEN 0 AND 16 && MONTH(`seq1`.call_date) = 9 && `seq1`.`client_object` = `client_objects`.`id` && YEAR(`seq1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `seq2` ON DAYOFMONTH(`seq2`.call_date) BETWEEN 17 AND 31 && MONTH(`seq2`.call_date) = 9 && `seq2`.`client_object` = `client_objects`.`id` && YEAR(`seq2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `oqt1`  ON DAYOFMONTH(`oqt1`.call_date) BETWEEN 0 AND 16 && MONTH(`oqt1`.call_date) = 10 && `oqt1`.`client_object` = `client_objects`.`id` && YEAR(`oqt1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree AS `oqt2`  ON DAYOFMONTH(`oqt2`.call_date) BETWEEN 17 AND 31 && MONTH(`oqt2`.call_date) = 10 && `oqt2`.`client_object` = `client_objects`.`id` && YEAR(`oqt2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `noe1` ON DAYOFMONTH(`noe1`.call_date) BETWEEN 0 AND 16 && MONTH(`noe1`.call_date) = 11 && `noe1`.`client_object` = `client_objects`.`id` && YEAR(`noe1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `noe2` ON DAYOFMONTH(`noe2`.call_date) BETWEEN 17 AND 31 && MONTH(`noe2`.call_date) = 11 && `noe2`.`client_object` = `client_objects`.`id` && YEAR(`noe2`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `dec1` ON DAYOFMONTH(`dec1`.call_date) BETWEEN 1 AND 16 && MONTH(`dec1`.call_date) = 12 && `dec1`.`client_object` = `client_objects`.`id` && YEAR(`dec1`.call_date) = YEAR(CURDATE())
						        LEFT JOIN services_degree  AS `dec2` ON DAYOFMONTH(`dec2`.call_date) BETWEEN 17 AND 31 && MONTH(`dec2`.call_date) = 12 && `dec2`.`client_object` = `client_objects`.`id` && YEAR(`dec2`.call_date) = YEAR(CURDATE())
						        WHERE  client_objects.actived = 1");
			
		$data = array(
			"aaData"	=> array()
		);
				
		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				if($i < 2){
						/* General output */
					$row[] = $aRow[$i];
				}else{
					switch( $aRow[$i] ){
						case '1':	$row[$i] = '<div style="background-color: green;  width: 23px !important; height: 23px !important;">&nbsp;</div>'; break;
						case '2':	$row[$i] = '<div style="background-color: yellow; width: 23px !important; height: 23px !important;">&nbsp;</div>'; break;
						case '3':	$row[$i] = '<div style="background-color: red;    width: 23px !important; height: 23px !important;">&nbsp;</div>'; break;
						default: 	$row[$i] = '<div style="background-color: white;  width: 23px !important; height: 23px !important;">&nbsp;</div>'; break;
					}					
				}
			}
			$data['aaData'][] = $row;
		}
	
		break;		    
	default:
		$error = "action null!";
}

$data['error'] = $error;

echo json_encode($data);

?>